package com.weiaibenpao.demo.chislim.ui.adapter;

import android.graphics.Typeface;
import android.support.annotation.LayoutRes;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.weiaibenpao.demo.chislim.R;
import com.weiaibenpao.demo.chislim.bean.ChinaRecordBean;
import com.weiaibenpao.demo.chislim.ui.widget.CirCleProgressBar;
import com.weiaibenpao.demo.chislim.utils.Utils;

/**
 * Created by wlx on 2018/1/2.
 */

public class RecordAdapter extends BaseQuickAdapter<ChinaRecordBean.ListBean,BaseViewHolder>{

public RecordAdapter(@LayoutRes int layoutResId) {
        super(layoutResId);
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, ChinaRecordBean.ListBean chinaRecordBean) {
        TextView tvDistance = (TextView) baseViewHolder.getView(R.id.tv_run_distance);
        baseViewHolder.setText(R.id.tv_run_distance,chinaRecordBean.getFinishDistance()+"");
        CirCleProgressBar progressBar = (CirCleProgressBar) baseViewHolder.getView(R.id.progress_bar);
        double progress = chinaRecordBean.getFinishDistance() / chinaRecordBean.getYudingDistance();

        if (progress>=1){
           progressBar.setProgress(100);
            tvDistance.setTypeface(null);
            tvDistance.setText("已跑完");
            baseViewHolder.getView(R.id.tv_is_over).setVisibility(View.GONE);
        }else {
            Typeface typeFace = Typeface.createFromAsset(mContext.getAssets(), "fonts/Reducto Condensed SSi Condensed.ttf");
            tvDistance.setTypeface(typeFace);
            progressBar.setProgress(progress<0.01?1:(int) (progress*100));
            tvDistance.setText(Utils.decimalFormat(chinaRecordBean.getFinishDistance())+"");
            baseViewHolder.getView(R.id.tv_is_over).setVisibility(View.VISIBLE);
        }
        baseViewHolder.setText(R.id.tv_total_distance,"共"+ Utils.decimalFormat(chinaRecordBean.getYudingDistance())+"公里");
        baseViewHolder.setText(R.id.tv_province_name,chinaRecordBean.getAreaAddress());
        baseViewHolder.setText(R.id.tv_run_time,"已用时："+Utils.getHmsTime(chinaRecordBean.getTotalTime()));
        //17-09-02 22：01
        baseViewHolder.setText(R.id.tv_last_time,"上次跑："+ Utils.getFormattedTime(chinaRecordBean.getCreateTime(),"yyyy-MM-dd HH:mm"));

    }
}
